## default build 32bit application
ARCH="-m32"
ARCH=

export ARCH

#gcc-prefix=mips-openwrt-linux-

CC ?= $(gcc-prefix)gcc

EXEC =  fish_server 
OBJS = fish_server.o \
	hal/thread_hal.o  \
	serial_driver.o  \
	modbus_rtu.o   \
	websocket_client.o \
	web_proxy.o

WEBSOCKET = libwebsocket

SERVER_EXEC = websocket_server

OBJS_SERVER = websocket_server.o \
	     main.o \
	     hal/thread_hal.o

CFLAGS += -g $(ARCH) -std=gnu99 -O0 -I. -I./include -fPIC -Ilibxlsxwriter/include

LDFLAGS +=  -lwebsockets -lpthread -lm -lrt -lz 

.PHONY: all $(EXEC) $(SERVER_EXEC)  $(WEBSOCKET)


all: $(EXEC) $(SERVER_EXEC) 

#%.o:%.c  
#	$(CC) -c $(CFLAGS) $< 

$(WEBSOCKET):
#	make -C libwebsockets -f makefile.mk

$(EXEC): $(OBJS) 
	$(CC) $(CFLAGS) -o $@ $(OBJS) -Llinux_host_lib $(LDFLAGS)

$(SERVER_EXEC): $(OBJS_SERVER)
	$(CC) $(CFLAGS) -o $@ $(OBJS_SERVER) -Llinux_host_lib -lxlsxwriter $(LDFLAGS) 


websocket_clean:
	make -C libwebsockets -f makefile.mk clean
	@rm -f  *.so*  libwebsocket.*
	@rm -f  lws_config.h libwebsockets.h
	
clean: 
	@rm -f $(EXEC) $(SERVER_EXEC) *.elf *.gdb *.o
	@rm -f $(OBJS) $(OBJS_SERVER)
#	@rm -f lws_config.h libwebsockets.h libwebsockets.a

distclean: clean
#	@make -C libwebsockets -f makefile.mk distclean

help:
	@echo " all // generate all"
	@echo " clean // clean all generate file"
	@echo " distclean   // do dist clean on  json / libwebsockets"
